package server

import (
	"fmt"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/go-kratos/kratos/v2/middleware/logging"
	"github.com/go-kratos/kratos/v2/transport/grpc"
	"go_private_im/api/logic"
	"go_private_im/internal/logic/conf"
	"go_private_im/internal/logic/service"
)

// NewGRPCServer new a gRPC server.
func NewGRPCServer(c *conf.Config, greeter *service.LogicService, zap log.Logger) *grpc.Server {
	var opts = []grpc.ServerOption{
		grpc.Middleware(
			logging.Server(zap),
		),
	}
	if c.RPCServer.Network != "" {
		opts = append(opts, grpc.Network(c.RPCServer.Network))
	}
	if c.RPCServer.Addr != "" {
		fmt.Println(c.RPCServer,"333333333333")
		opts = append(opts, grpc.Address(c.RPCServer.Addr))
	}
	if c.RPCServer.Timeout != 0 {
		opts = append(opts, grpc.Timeout(c.RPCServer.Timeout))
	}
	srv := grpc.NewServer(opts...)
	logic.RegisterLogicServer(srv, greeter)
	return srv
}
